aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/(dash)/chat/[chatid]/page.tsx
blob: 96e960209b72b58285f6e345b253a8f26d3f281e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { getFullChatThread } from "@/app/actions/fetchers";
import { chatSearchParamsCache } from "@/lib/searchParams";
import ChatWindow from "../chatWindow";

async function Page({
  params,
  searchParams,
}: {
  params: { chatid: string };
  searchParams: Record<string, string | string[] | undefined>;
}) {
  const { firstTime, q, spaces } = chatSearchParamsCache.parse(searchParams);

  let chat: Awaited<ReturnType<typeof getFullChatThread>>;

  try {
    chat = await getFullChatThread(params.chatid);
  } catch (e) {
    const error = e as Error;
    return <div>This page errored out: {error.message}</div>;
  }

  if (!chat.success || !chat.data) {
    console.error(chat.error);
    return <div>Chat not found. Check the console for more details.</div>;
  }

  return (
    <ChatWindow
      q={q}
      spaces={spaces ?? []}
      initialChat={chat.data.length > 0 ? chat.data : undefined}
      threadId={params.chatid}
    />
  );
}

export default Page;